package com.fzu.messageservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fzu.commonutil.ImResult;
import com.fzu.commonutil.entity.ImChatUserFriend;
import com.fzu.commonutil.entity.User;
import com.fzu.commonutil.util.ImUtil;
import com.fzu.messageservice.client.NormalClient;
import com.fzu.messageservice.service.ImChatUserFriendService;
import com.fzu.messageservice.vo.UserFriendVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


/**
 * 好友(ImChatUserFriend)表控制层
 *
 * @author Answer
 * @since 2023-04-04 21:46:15
 */
@Slf4j
@RestController
@RequestMapping("/imChatUserFriend")
public class ImChatUserFriendController {
    /**
     * 服务对象
     */
    @Autowired
    private NormalClient normalClient;

    /**
     * 查询好友
     */
    @GetMapping("/getFriend")
//    @LoginCheck
    public ImResult<List<UserFriendVO>> getFriend() {
        log.info("访问此方法");
        Integer userId = ImUtil.getUserId();
        List<User> users = normalClient.getAllUser(userId.toString());
        List<UserFriendVO> userFriendVOS = new ArrayList<>(users.size());
        users.forEach(user -> {
            if (user != null) {
                UserFriendVO userFriendVO = new UserFriendVO();
//                userFriendVO.setId(userFriend.getId());
                userFriendVO.setUserId(userId);
                userFriendVO.setFriendId(user.getId());
                userFriendVO.setCreateTime(user.getCreateTime());
                userFriendVO.setRemark(user.getNickName());
                userFriendVO.setFriendStatus(1);
                userFriendVO.setUsername(user.getNickName());
                userFriendVO.setCompanyId(user.getCompanyId());
                userFriendVOS.add(userFriendVO);
            }
        });
        return ImResult.success(userFriendVOS);
    }
}

